package com.zzyl.nursing.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.zzyl.common.core.domain.R;
import com.zzyl.nursing.domain.DeviceData;
import com.zzyl.nursing.dto.DeviceDto;
import com.zzyl.nursing.vo.DeviceDetailVo;
import com.zzyl.nursing.vo.DeviceReportedVo;
import com.zzyl.nursing.vo.ProductVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.zzyl.common.annotation.Log;
import com.zzyl.common.core.controller.BaseController;
import com.zzyl.common.core.domain.AjaxResult;
import com.zzyl.common.enums.BusinessType;
import com.zzyl.nursing.domain.Device;
import com.zzyl.nursing.service.IDeviceService;
import com.zzyl.common.utils.poi.ExcelUtil;
import com.zzyl.common.core.page.TableDataInfo;

/**
 * deviceController
 * 
 * @author LiuLi
 * @date 2025-08-21
 */
@Api(tags = "device管理")
@RestController
@RequestMapping("/nursing/device")
public class DeviceController extends BaseController
{
    @Autowired
    private IDeviceService deviceService;


    /**
     * 同步device列表
     */
    @ApiOperation("同步device列表")
    @PreAuthorize("@ss.hasPermi('nursing:device:syncProductList')")
    @PostMapping("/syncProductList")
    public AjaxResult syncProductList() {
        deviceService.syncProductList();
        return AjaxResult.success();
    }

    /**
     * 查询device列表
     */
    @ApiOperation("查询device列表")
    @PreAuthorize("@ss.hasPermi('nursing:device:allProduct')")
    @GetMapping("/allProduct")
    public R<List<ProductVo>> listAllProduct(@ApiParam("device查询条件") DeviceData deviceData)
    {
        List<ProductVo> list = deviceService.listAllProduct();
        return R.ok(list);
    }
    /**
     * 注册设备
     */
    @ApiOperation("注册设备")
    @PreAuthorize("@ss.hasPermi('nursing:device:register')")
    @PostMapping("/register")
    public AjaxResult add(@ApiParam("device信息") @RequestBody DeviceDto deviceDto) {
        deviceService.registerDevice(deviceDto);
        return success();
    }
    /**
     * 查询设备详情
     */
    @ApiOperation("查询设备详情")
    @GetMapping("/{id}")
    public R<DeviceDetailVo> getInfo(@ApiParam("deviceID") @PathVariable("id") String iotId) {
        DeviceDetailVo device = deviceService.getByIotId(iotId);
        return R.ok(device);
    }

    /**
     * 查询设备上报数据
     */
    @ApiOperation("查询设备上报数据")
    @PreAuthorize("@ss.hasPermi('nursing:device:reportedData')")
    @GetMapping("/queryServiceProperties/{iotId}")
    public R<List<DeviceReportedVo>> queryServiceProperties(@PathVariable("iotId") String iotId) {
        List<DeviceReportedVo> list = deviceService.queryServiceProperties(iotId);
        return R.ok(list);
    }







































    /**
     * 查询device列表
     */
    @ApiOperation("查询device列表")
    @PreAuthorize("@ss.hasPermi('nursing:device:list')")
    @GetMapping("/list")
    public TableDataInfo<List<Device>> list(@ApiParam("device查询条件") Device device) {
        startPage();
        List<Device> list = deviceService.selectDeviceList(device);
        return getDataTable(list);
    }

//    /**
//     * 导出device列表
//     */
//    @ApiOperation("导出device列表")
//    @PreAuthorize("@ss.hasPermi('nursing:device:export')")
//    @Log(title = "device", businessType = BusinessType.EXPORT)
//    @PostMapping("/export")
//    public void export(@ApiParam(value = "device查询条件") HttpServletResponse response, DeviceReportedVo device)
//    {
//        List<DeviceReportedVo> list = deviceService.selectDeviceList(device);
//        ExcelUtil<DeviceReportedVo> util = new ExcelUtil<DeviceReportedVo>(DeviceReportedVo.class);
//        util.exportExcel(response, list, "device数据");
//    }
//
//    /**
//     * 获取device详细信息
//     */
//    @ApiOperation("获取device详细信息")
//    @PreAuthorize("@ss.hasPermi('nursing:device:query')")
//    @GetMapping(value = "/{id}")
//    public R<DeviceReportedVo> getInfo(@ApiParam("deviceID") @PathVariable("id") Integer id)
//    {
//        return R.ok(deviceService.selectDeviceById(id));
//    }
//
//    /**
//     * 新增device
//     */
//    @ApiOperation("新增device")
//    @PreAuthorize("@ss.hasPermi('nursing:device:add')")
//    @Log(title = "device", businessType = BusinessType.INSERT)
//    @PostMapping
//    public AjaxResult add(@ApiParam("device信息") @RequestBody DeviceReportedVo device)
//    {
//        return toAjax(deviceService.insertDevice(device));
//    }
//
//    /**
//     * 修改device
//     */
//    @ApiOperation("修改device")
//    @PreAuthorize("@ss.hasPermi('nursing:device:edit')")
//    @Log(title = "device", businessType = BusinessType.UPDATE)
//    @PutMapping
//    public AjaxResult edit(@ApiParam("device信息") @RequestBody DeviceReportedVo device)
//    {
//        return toAjax(deviceService.updateDevice(device));
//    }
//
//    /**
//     * 删除device
//     */
//    @ApiOperation("删除device")
//    @PreAuthorize("@ss.hasPermi('nursing:device:remove')")
//    @Log(title = "device", businessType = BusinessType.DELETE)
//	@DeleteMapping("/{ids}")
//    public AjaxResult remove(@ApiParam("deviceID数组") @PathVariable Integer[] ids)
//    {
//        return toAjax(deviceService.deleteDeviceByIds(ids));
//    }
}
